﻿using AutoMapper;
using Hotel.Common;
using Hotel.Domain;
using Hotel.IServices;
using Hotel.IServices.RequestDTO;
using Hotel.IServices.ResponseDTO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class GoodsController : ControllerBase
    {
        private readonly ILogger<GoodsController> logger;
        private readonly IGoodsServices goodsServices;

        public GoodsController(ILogger<GoodsController> logger, IGoodsServices goodsServices)
        {
            this.logger = logger;
            this.goodsServices = goodsServices;
        }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("AddGoodsAsync")]

        
        public async Task<ApiResult> AddGoodsAsync(AddGoodsAsyncReDto dto)
        {
            try
            {
                return await goodsServices.AddGoodsAsync(dto);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 分页查询商品列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet("QueryGoodsListPagedAsync")]
        public async Task<ApiResult<PagingResult<IList<QueryGoodsListPagedAsyncRespDto>>>> QueryGoodsListPagedAsync([FromQuery]QueryGoodsListPagedAsyncReqDto dto)
        {
            try
            {
                return await goodsServices.QueryGoodsListPagedAsync(dto);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="goodid"></param>
        /// <returns></returns>
        /// 
        [HttpDelete("DelGoodsAsync")]
        public async Task<ApiResult> DelGoodsAsync(long goodid)
        {
            try
            {
                return await goodsServices.DelGoodsAsync(goodid);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 根据id查询商品信息
        /// </summary>
        /// <param name="goodid"></param>
        /// <returns></returns>
        /// 
        [HttpGet("UpSqlUser")]
        public async Task<ApiResult> UpSqlUser(long goodid)
        {
            try
            {
               return await goodsServices.UpSqlUser(goodid);
            }
            catch (Exception)
            {

                throw;
            }

        }


        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPut("UpUser")]
        public async Task<ApiResult> UpUser(GetUpGoodsReDto dto)
        {
            try
            {
                return await goodsServices.UpUser(dto);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
